{template 'common/header'}
<ul class="nav nav-tabs">
	<li {if $op == 'post'}class="active"{/if}><a href="{php echo $this->createWebUrl('games',array('op'=>'post'))}">添加游戏</a></li>
	<li {if empty($op) || $op == 'display'}class="active"{/if}><a href="{php echo $this->createWebUrl('games')}">游戏列表</a></li>
</ul>
{if $op == 'display'}
<style>
th{
	text-align: center !important;
}
td{
	text-align: center !important;
	white-space: normal !important;
	word-break: break-all !important;
}
</style>
<form action="" method="get" class="form-horizontal" role="form">
<div class="panel panel-info">
        <div class="panel-heading">筛选</div>
        <div class="panel-body">
                <input type="hidden" name="c" value="site" />
                <input type="hidden" name="a" value="entry" />
                <input type="hidden" name="m" value="junsion_challeng" />
                <input type="hidden" name="do" value="games" />
                <div class="form-group">
                    <label class="col-xs-12 col-sm-2 col-md-2 col-lg-1 control-label">关键字</label>
                    <div class="col-xs-12 col-sm-9 col-lg-9">
                        <input class="form-control" name="keyword" type="text" value="{$_GPC['keyword']}" placeholder="请输入游戏名称">
                    </div>
                </div>
                
                <div class="form-group">
                	<label class="col-xs-12 col-sm-2 col-md-2 col-lg-1 control-label"></label>
                    <div class=" col-xs-12 col-sm-2 col-lg-2">
                        <button class="btn btn-default" ><i class="fa fa-search"></i> 搜索</button>
                   	</div>
                </div>
                
        </div>
    </div>
</form>

<div class="panel panel-default">
    <div class="table-responsive panel-body">
        <table class="table table-hover">
            <thead class="navbar-inner">
            <tr>
            	<th>排序</th>
            	<th>游戏名称</th>
                <th>logo</th>
                <th>浏览次数</th>
                <th>appid<br/>链接</th>
                <th>状态</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody id="level-list">
            {loop $list $item}
            <tr>
            	<td>{$item['sort']}</td>
            	<td>{$item['title']}</td>
                <td><img src="{php echo toimage($item['thumb'])}" style="width:60px;"></td>
                <td>虚拟：{$item['dummy_num']}<br/>实际：{$item['num']}</td>
                <td>{$item['appid']}<br/>{$item['url']}</td>
                <td data-id='{$item["id"]}'>{if $item['status']}<label class="label label-success">显示</label>{else}<label class="label label-default">隐藏</label>{/if}</td>
               <td>
                   <a class="btn btn-default btn-sm" href="{php echo $this->createWebUrl('games', array('op' => 'post', 'id' => $item['id']))}">编辑</a>
                   <a class="btn btn-danger btn-sm" onclick="return confirm('确认删除吗？');return false;" href="{php echo $this->createWebUrl('games', array('op' => 'del', 'id' => $item['id']))}">删除</a>
                </td>
            </tr>
            {/loop}
            </tbody>
        </table>
        {$pager}
    </div>
<script>
$('table label').click(function(){
	var label = $(this);
	$.ajax({
		url:"{php echo $this->createWebUrl('games',array('op'=>'status'))}",
		type:'post',
		data:{id:label.parent().attr('data-id')},
		success:function(status){
			if(status == '1'){
				if(label.hasClass('label-success')){
					label.removeClass('label-success').addClass('label-default');
					label.text('隐藏');
				}else{
					label.removeClass('label-default').addClass('label-success');
					label.text('显示');
				}
			}
		}
	});
});
</script>    
</div>

{elseif $op == 'post'}

<div class="panel panel-info">
		<div class="panel-body">
			<form action="" method="post" class="form-horizontal" role="form">
			<input type="hidden" name="id" value="{$item[id]}">
			{php load()->func('tpl')}
			<div class="form-group">
				<label class="col-xs-12 col-sm-2 col-md-2 col-lg-1 control-label">排序</label>
				<div class="col-sm-9">
					<input class="form-control" name="sort" id='sort' type="number" min='0' value="{$item['sort']}">
				</div>
			</div>
			<div class="form-group">
				<label class="col-xs-12 col-sm-2 col-md-2 col-lg-1 control-label"><span style="color:red;">*</span>游戏名称</label>
				<div class="col-sm-9">
					<input class="form-control" required="required" name="title" id='title' type="text" value="{$item['title']}">
				</div>
			</div>
			<div class="form-group">
	            <label class="col-xs-12 col-sm-2 col-md-2 col-lg-1 control-label">游戏logo</label>
	            <div class="col-sm-9 col-xs-12">
	               	{php echo tpl_form_field_image('thumb',$item['thumb']);}
	<div class="help-block">建议上传1:1比例的图片</div>
	            </div>
	        </div>
	        <div class="form-group">
				<label class="col-xs-12 col-sm-2 col-md-2 col-lg-1 control-label">简述</label>
				<div class="col-sm-9">
					<input class="form-control" name="des" id='des' type="text" value="{$item['des']}">
				</div>
			</div>
			
			<div class="form-group">
	            <label class="col-xs-12 col-sm-2 col-md-2 col-lg-1 control-label"></label>
	            <div class="col-sm-9 col-xs-12">
	<div class="help-block" style="color:red;">注意：若跳转小程序，请输入appid。若跳转小程序，填小程序页面路径；若跳转网页，请填https链接；若跳转本小程序的链接也无需填写appid。</div>
	            </div>
	        </div>
			
			<div class="form-group">
				<label class="col-xs-12 col-sm-2 col-md-2 col-lg-1 control-label">appid</label>
				<div class="col-sm-9">
					<input class="form-control" name="appid" id='appid' type="text" value="{$item['appid']}">
				</div>
			</div>
			<div class="form-group">
				<label class="col-xs-12 col-sm-2 col-md-2 col-lg-1 control-label">链接</label>
				<div class="col-sm-9">
					<input class="form-control" name="url" id='url' type="text" value="{$item['url']}">
				</div>
			</div>
	        <div class="form-group">
            	<label class="col-xs-12 col-sm-2 col-md-2 col-lg-1 control-label">虚拟浏览次数</label>
            	<div class="col-sm-9">
                	<div class='input-group'>
			    		<input type="number" name="dummy_num" value="{$item['dummy_num']}" class="form-control"/>
						<span class='input-group-addon'>次</span>
		            </div>
            	</div>
          	</div>
			<div class="form-group">
				<label class="col-xs-12 col-sm-2 col-md-2 col-lg-1 control-label">状态</label>
				<div class="col-sm-9">
					<label><input type="radio" name="status" {if empty($item['status'])}checked="checked"{/if} value="0"> 隐藏</label>
					<label style="margin-left: 10px;"><input type="radio" name="status" {if $item['status']}checked="checked"{/if} value="1"> 显示</label>
				</div>
			</div>
			
			<button type="submit" class="btn btn-primary" name="submit" id='summit_info' value="提交">保存</button>
			<input type="hidden" name="token" value="{$_W['token']}" />
			</form>
	</div>
</div>
<script>

$(function(){
	$("#summit_info").click(function(){
		var title = $("#title").val();
		if(!title){
			alert("请输入游戏名称");
			return false;
		}
	});
});
</script>
{/if}
{template 'common/footer'}